#include <hidef.h>      /* common defines and macros */
#include "includes.h" 

extern int speednow;
extern int Left,Right,coordinate;

extern int Averagevalue,Value[3],w_flag,cc_flag,z_flag;

extern unsigned int change_tempp,change_temps;
extern unsigned int ss;
extern float spp,sdd;

unsigned int abs(int a)   //取绝对值
{ 
  return (a>=0?a:-a);
}

void speedget(void) 
{
  speednow=PACNT;
  PACNT=0;
}

void car_control(void) 
{   
   static int path0=0,path1=0,path2=0;
  
   speedget();          //读取速度脉冲 
   if(cc_flag==1) 
   {
     PathOperation();     //道路识别 
     cc_flag=0;
   }
   
   
  
  
  /* if(w_flag==0)       //直道
   {
     Steer_PD(spp,sdd,coordinate);
     Motor_PID(ss+20);
   }
   if(abs((int)Averagevalue)>=15||w_flag==1)       //入弯
   {
     Steer_PD(spp,sdd,coordinate);
     Motor_PID(ss-40);
   }
   if(abs((int)Averagevalue)>=15||w_flag==2)       //出弯
   {
     Steer_PD(spp,sdd,coordinate);
     Motor_PID(ss);
   } */  
   
 
/*  if(abs((int)Averagevalue)<15&&(path0<=10))         //短直道入弯
   { 
      z_flag=0;
      path0++;
      Steer_PD(5,7,coordinate);
      Motor_PID(ss+10); 
   } 
   else if(abs((int)Averagevalue)<15&&Value[0]<15&&(path0>10)) //常直道
   { 
      path1=0; 
      path2=1;  
        
      Steer_PD(5,6.5,coordinate);
      Motor_PID(ss+20); 
   } 
   else if (Value[0]>=15&&z_flag>20&&path1<25)             //常直道入弯道
   {
      z_flag=0;
      path0 =0;
      path1++;

      Steer_PD(spp,sdd,coordinate);
      Motor_PID(ss-30); 
   } 
       
   else if (abs((int)Averagevalue)>=15&&path1>=25)          //纯弯道
   {
      z_flag=0;
      path0 =0;
      path1++;
        
      Steer_PD(spp,sdd,coordinate);
      Motor_PID(ss+10); 
   } 
   else
   
   {
      z_flag=0;
      Steer_PD(spp,sdd,coordinate);
      Motor_PID(ss+10); 
   
   }   */
   
    
    if(abs((int)Averagevalue)<10&&(path0<=10)) 
      
       { 
        path0++;
        Steer_PD(spp,7,coordinate);
        Motor_PID(ss+10); 
       } 
      
     
      if(abs((int)Averagevalue)<10&&(path0>10)) 
       { 
        path1=0; 
        path2=1;  
        
        Steer_PD(spp,sdd,coordinate);
        Motor_PID(ss+20); 
       } 
       else if (abs((int)Averagevalue)>=10&&path1<20)
       {
       
        path0 =0;
        path1++;

        Steer_PD(spp,sdd,coordinate);
        Motor_PID(ss-30); 
       } 
       
       else if (abs((int)Averagevalue)>=10&&path1>19)
       {
        path0 =0;
        path1++;
        
        Steer_PD(spp,sdd,coordinate);
        Motor_PID(ss+10); 
       }  
   
   
        else  
       {
       
        Steer_PD(spp,sdd,coordinate);
        Motor_PID(ss); 
       } 
   
   
      
   
   
            

}